﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GMS
{
    /// <summary>
    /// Summary description for SessionVariable
    /// </summary>
    [Serializable]
    public class SessionVariable
    {
        #region Constructor

        public SessionVariable()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #endregion Constructor

        private const string SESSION_KEY = "_!userDetails";
        public static SessionVariable Instance
        {
            get
            {
                if (HttpContext.Current.Session != null && HttpContext.Current.Session[SESSION_KEY] != null)
                {
                    return (SessionVariable)HttpContext.Current.Session[SESSION_KEY];
                }
                else
                {
                    SessionVariable session = new SessionVariable();
                    HttpContext.Current.Session[SESSION_KEY] = session;
                    return session;
                }
            }
        }

        private UserSession _userDetails = new UserSession();
        public UserSession UserDetails
        {
            get
            {
                return _userDetails;
            }
            set
            {
                _userDetails = value;
                HttpContext.Current.Session[SESSION_KEY] = value;
            }
        }

        public class UserSession
        {
            #region Constructor

            public UserSession()
            {
                _options = new BLL.Entities.Options();
                _cost = new BLL.Entities.Cost();
                _shape = new List<BLL.Entities.ShapeDimension>();
            }

            #endregion Constructor

            #region Properties

            private BLL.Entities.Options _options;
            public BLL.Entities.Options Options
            {
                get
                {
                    return _options;
                }
                set
                {
                    _options = value;
                }
            }

            #region User

            public int UserId { get; set; }

            public bool IsAdmin { get; set; }

            public string Name { get; set; }

            public string Email { get; set; }

            public string PhoneNumber { get; set; }

            public bool IsContactedByPhone { get; set; }

            public bool IsDataPersisted { get; set; }

            #endregion User

            private BLL.Entities.Cost _cost;
            public BLL.Entities.Cost Cost
            {
                get
                {
                    return _cost;
                }
                set
                {
                    _cost = value;
                }
            }

            public int ShapeId { get; set; }

            public string SelectedMaterialType { get; set; }

            public string SelectedShapeUrl { get; set; }

            public string SelectedShapeEnterInputsUrl { get; set; }

            private List<BLL.Entities.ShapeDimension> _shape;
            public List<BLL.Entities.ShapeDimension> Shape
            {
                get
                {
                    return _shape;
                }
                set
                {
                    _shape = value;
                }
            }

            public int ZipCode { get; set; }

            public int SelectedStoneTypeId { get; set; }

            public int SelectedStoneCategoryId { get; set; }

            #endregion Properties
        }
    }
}